/**
 * Written By: MinHo Kim (minho.kim.korea@gmail.com)
 * Copyright (C) 2011, MinHo Kim, Software Expert Program, KAIST University, Seoul, Korea.
 * This program is free software; you can redistribute it and/or modify it 
 * under the terms of the GNU General Public License as published 
 * by the Free Software Foundation; version 2 of the License.
 * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; 
 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  
 * See the GNU General Public License for more details.
 */
package kaist.sep502.tsp.util;

/**
 * @author minho kim
 *
 */
public class StopWatch {
	private long startTime;
	private long elapsedTime;
	
	public StopWatch(){
		startTime = System.nanoTime();
	}
	
	public void stop(){
		elapsedTime = System.nanoTime() - startTime;
	}
	
	public double getElapsedMS(){
		if(elapsedTime == 0) stop();
		
		return elapsedTime / 1000000.0;
	}
	
	public double getElapsedNano(){
		if(elapsedTime == 0) stop();
		
		return elapsedTime;
	}
	
	/* (non-Javadoc)
	 * @see java.lang.Object#toString()
	 */
	@Override
	public String toString() {
		if(elapsedTime == 0) stop();
		double ms = (elapsedTime/1000000000.0);
		long minutes = (int) ms / 60;
		long seconds = (int) ms % 60;
		
		return ms + "ms (" + minutes + "분 " + seconds + "초)" ;
	}
}
